#include "StaticAlgorithmDesigner.h"
#include "ui_StaticAlgorithmDesigner.h"

#include <QMessageBox>

using namespace RafMat::SimInterface;

StaticAlgorithmDesigner::StaticAlgorithmDesigner(QWidget *parent) :
    AdaptiveAlgorithmDesignerBase(parent),
    ui(new Ui::StaticAlgorithmDesigner)
{
    ui->setupUi(this);
}

StaticAlgorithmDesigner::~StaticAlgorithmDesigner()
{
    delete ui;
}

void StaticAlgorithmDesigner::attachAlgorithm(RafMat::SimInterface::IConfigurableSPtr ctrl)
{
    m_targetAlgorithm = ctrl;

    try
    {
        ui->txtRPoly->setText(QString::fromStdString(m_targetAlgorithm->getParameter("adpt::rpoly")));
        ui->txtSPoly->setText(QString::fromStdString(m_targetAlgorithm->getParameter("adpt::spoly")));
        ui->txtTPoly->setText(QString::fromStdString(m_targetAlgorithm->getParameter("adpt::tpoly")));
        ui->txtHValue->setText(QString::fromStdString(m_targetAlgorithm->getParameter("adpt::h")));
    }
    catch(iconf_error& e)
    {
        QMessageBox::warning(this, "Error", e.what());
    }
}


void StaticAlgorithmDesigner::applySettings()
{
    try
    {
        m_targetAlgorithm->setParameter("adpt::rpoly", ui->txtRPoly->text().toStdString());
        m_targetAlgorithm->setParameter("adpt::spoly", ui->txtSPoly->text().toStdString());
        m_targetAlgorithm->setParameter("adpt::tpoly", ui->txtTPoly->text().toStdString());
        m_targetAlgorithm->setParameter("adpt::h", ui->txtHValue->text().toStdString());
    }
    catch(iconf_error& e)
    {
        QMessageBox::warning(this, "Error", e.what());
    }
}
